<?php
/*
 * @分销商城
 * @功能说明：客户管理中心
 * @更新说明：暂无更新
 * @文件名 IndexController.class.php
 * @编码 UTF-8
 * @创建时间 2015-12-25 下午1:46:53
 * @创建人 XING
 */
namespace bj\Controller;
use Think\Controller;
header("Content-type: text/html; charset=utf-8");
class IndexController extends ApibaseController {
	/*
	 * 用户列表
	 * @date: 2015-6-2 上午11:04:55
	 * @editor: XING
	 */
    public function index(){
		redirect('/goods/index');exit;
    	/*参数初始化*/
    	$page = I('get.page') ?: 1;
    	$perpage = 10;$url = '';
    	$list = M('CustEntity');
    	$url = $output = $outtype = array();
    	if(I('get.cust_name')){
    		$list = $list->where('cust_realname LIKE "%'.I('get.cust_name').'%"');
    		$url['cust_name'] = I('get.cust_name');
    	}
    	if(I('get.cust_mobile')){
    		$list = $list->where(array('cust_mobile'=>I('get.cust_mobile')));
    		$url['cust_mobile'] = I('get.cust_mobile');
    	}
    	if(I('get.cust_id')){
    		$list = $list->where(array('cust_id'=>I('get.cust_id')));
    	}

    	$custObject = clone $list;
    	$getData = $list->order(array('add_at'=>'desc'))->page($page,$perpage)->select();
    	$this->assign('page',setPage($custObject->count(),$perpage,$page,'?'.http_build_query($url)));
    	$this->assign('getData',$getData);
    	
    	$this->display('index/index');
    }
    
	/*
	 * 用户编辑
	 * @date: 2015-6-2 下午12:08:52
	 * @editor: XING
	 */
    public function addcust(){
    	if(I('post.dosubmit')){
    		$data = array(
    			'cust_realname' => I('post.cust_realname'),
    			'hy' => I('post.hy'),
    			'job' => I('post.job'),
    		);
    		if($data){
    			if(I('post.cust_id')){
	    			M('CustEntity')->where(array('cust_id'=>I('post.cust_id')))->setField($data);
	    			putlog('用户信息修改 `'.I('post.cust_realname').'`','IndexController','addcust');
	    			$this->showtips('更新成功');
    			}else{
    				M('CustEntity')->add(array_merge($data,array('add_at'=>time())));
    				putlog('用户信息添加 `'.I('post.cust_realname').'`','IndexController','addcust');
    				$this->showtips('用户添加成功');
    			}
    		}else{
    			$this->showtips('操作失败');
    		}
    	}elseif(I('get.cust_id')){
    		$custData = M('CustEntity')
    				  ->where(array('cust_id'=>I('get.cust_id')))->find();
    		$this->assign('custData',$custData);
    		$this->display('index/addcust');
    	}
    	
    	$this->display('index/addcust');
    }
    
	/*
	 * 冻结&解封用户
	 * @date: 2015-6-2 下午2:34:17
	 * @editor: XING
	 */
    public function decate(){
		if(I('get.types')){
			M('CustEntity')->where(array('cust_id'=>I('get.custid')))->setField(array(
					'check' => '1'
				));
			$this->showtips('成功解封该用户');		
		}
    	M('CustEntity')->where(array('cust_id'=>I('get.custid')))->setField(array(
    			'check' => '0'
    		));
    	$this->showtips('成功冻结该用户');
    }

	/*
	 * 定时统计功能
	 * @date: 2015-6-3 下午4:22:19
	 * @editor: XING
	 */
    public function getCountCj(){
    	$tj_life_regist = M('CustEntity')->where('add_at > '.strtotime(date('Y-m-d')).' AND add_at < '.time())->count();
    	$tj_life_port = M('ReportEntity')->where('add_at > '.strtotime(date('Y-m-d')).' AND add_at < '.time())->count();
    	session(array('expire'=>360000));
    	session('tj_life',time());
    	session('tj_life_regist',$tj_life_regist);
    	session('tj_life_port',$tj_life_port);
    }

}